<script type="">    

    //-----------------------------------------------------------------------------------------------------------------//   

    var filename = "";
    var filepath = "";
    function getdata(data_json){              
        var json = $.parseJSON(data_json);
        var code = json.code;   

        if(code == '105')
            {
            filename = json.data["filename"];

            //filetype = json.data["filetype"];
            //filesize = json.data["filesize"];
            filepath = "/" + json.data["forder_up"]  + "/" + ""+filename;
            path = "<?=Yii::app()->params['urlImage']?>/"+ json.data["forder_up"]  + "/" + ""+filename;            
            //path = "http://images.az24.vn"+ json.data["path"]  + "/" + ""+filename;            
            $("#txtFileName").val(filepath);
            //$("#thumbnails").html("<img style='max-height: 200px;max-width: 200px;' src='"+path+"'/>");                          
        }
        else
            {
            var msg = json.msg;                
            alert(msg);    
        }
    }

    //-----------------------------------------------------------------------------------------------------------------//

    var swfu;
    window.onload = function () {
        swfu = new SWFUpload({
            // Backend Settings
            upload_url: "<?=$link_url ?>",
            post_params: "resume_file",

            // File Upload Settings
            file_size_limit : "4 MB",
            file_types : "*.doc;*.docx;*.xls;*.xlsx;*.pdf;*.rar",
            file_types_description : "Tài liệu",
            file_upload_limit : "0",

            file_queue_error_handler : fileQueueError,
            file_dialog_complete_handler : fileDialogComplete,
            upload_progress_handler : uploadProgress,
            upload_error_handler : uploadError,
            upload_success_handler : uploadSuccess,
            upload_complete_handler : uploadComplete,

            // Button Settings
            button_image_url : "<?php echo Yii::app()->params['urlRs']; ?>/js/swfupload/XPButtonUploadText_61x22.png",
            button_placeholder_id : "spanButtonPlaceholder",
            button_width: 61,
            button_height: 22,

            // Flash Settings
            flash_url : "<?php echo Yii::app()->params['urlRs']; ?>/js/swfupload/swfupload.swf",

            custom_settings : {
                upload_target : "divFileProgressContainer"
            },

            // Debug Settings
            //debug: true
        });
    };

    //-----------------------------------------------------------------------------------------------------------------//

    function send_asignment(group_id,user_id){
        var assignment_title = $('#assignment_title').val();;
        var assignment_description = $('#assignment_description').val();;
        var assignment_link = filepath;              
        var assignment_file_name = filename;              
        if(assignment_title == ''){
            /*$('#stt_content_error').slideDown('slow');*/            
            //show_error('assignment_title_error','Tiêu đề bài tập không được để trống!');
            $('#assignment_title_error').html('Tiêu đề bài tập không được để trống!');        
            $('#assignment_title_error').show('slow');              
            return false;
        }            
        
        $('.err').hide();
                  
        var strUrl = '<?=$url->createUrl("group/ajaxSendAssignment") ?>';            
        loadingAjax();        
        $.ajax({
            type: "GET",
            url: strUrl,
            data: {group_id:group_id,user_id:user_id,assignment_title:assignment_title,assignment_description:assignment_description,assignment_link:assignment_link,assignment_file_name:assignment_file_name},
            success: function(msg){                            
                if(msg==1){                                           
                    location.reload(true);
                }
            }
        });
        closeLoadingAjax();          
                          
                                    
    }    
    
    function send_reply(assignment_id,user_id,group_id){        
        var reply_content = $('#content_reply_'+assignment_id).val();        
        
        if(reply_content == ''){
            /*$('#stt_content_error').slideDown('slow');*/
            show_error('error_reply_'+post_id,'Trả lời của bạn không được để trống!');
            return false;
        }        
        
        $('.empty-reply-error').hide();
        
        var strUrl = '<?=$url->createUrl("group/ajaxSendAssignmentReply") ?>';            
        loadingAjax();        
        $.ajax({
            type: "GET",
            url: strUrl,
            data: {assignment_id:assignment_id,reply_content:reply_content,user_id:user_id,group_id:group_id},
            success: function(msg){                            
                if(msg==1){                                           
                    location.reload(true);
                }else if(msg==-3){                    
                    show_error('receiver_name_error','Người dùng không tồn tại!');
                    $('#receiver_name').focus();        
                    return false;                    
                }

            }
        });
        closeLoadingAjax();          
        
    }
                                        
    function show_error(div_id,text){
        $('.err').hide();
        $('.empty-reply-error').hide('slow');
        $('#'+div_id).html(text);        
        $('#'+div_id).show('slow');      
        
    }
    
    function show_btn_reply(p_id){        
        $('.empty-reply-error').hide('slow');
        $('#content_reply_'+p_id).html('');        
        $('#btn_reply_'+p_id).slideDown('slow');        
    }

</script>